package com.etone.autotesting.test;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;

import org.apache.log4j.Logger;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;

import com.etone.autotesting.manager.impl.ServiceThreadRunable;
import com.etone.autotesting.socketservice.impl.NettyServerHandler;
import com.etone.ejb.core.util.PropertiesUtil;

public class NettyServer {

	protected static Logger logger = Logger.getLogger(NettyServer.class.getName());

	/**
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		// Configure the server.
		ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));

		// Set up the pipeline factory.
		bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
			public ChannelPipeline getPipeline() throws Exception {
				return Channels.pipeline(new NettyServerHandler());
			}
		});
		String nettyPort = PropertiesUtil.getInstance().getValue("nettyPort");
		String nettyIP = PropertiesUtil.getInstance().getValue("nettyIP");
		// Bind and start to accept incoming connections.
		bootstrap.bind(new InetSocketAddress(nettyIP, Integer.valueOf(nettyPort)));
		logger.info("Netty(" + nettyIP + "," + nettyPort + ")启动成功！");
	}
}
